<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p id="p1"></p>
    <script>

        let p = document.querySelector("#p1");

        let offDate = new Date();
        offDate.setHours(20);
        offDate.setMinutes(30);
        offDate.setSeconds(0);
        offDate.setMilliseconds(0);
        // 返回时间戳
        let offTime = offDate.getTime();

        let id = setInterval(function() {
            let now = new Date();
            let nowTime = now.getTime();
            let diff = offTime - nowTime;

            if (diff <= 0) {
                p.innerText  = "下班了";
                clearInterval(id);
                return;
            } 

            // 变为秒数
            diff /= 1000;

            let hours = Math.floor(diff / 3600);

            let minutes = Math.floor(diff % 3600 / 60);

            // 秒数
            let seconds = Math.floor(diff % 60);

            p.innerText = `离下班时间还有${hours}小时${minutes}分钟${seconds}秒`;
        },1000)

    </script>
</body>
</html>